package com.batch.avgleclient.model

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = arrayOf(AvCategory.Response.Category::class), version = 1)
abstract class AvCategoryDatabase: RoomDatabase() {
    abstract fun avCategoryDao(): AvCategoryDao

    companion object {
        @Volatile private var instance: AvCategoryDatabase? = null
        private val LOCK = Any()

        operator fun invoke(context: Context) = instance ?: synchronized(LOCK) {
            instance ?: buildDatabase(context).also {
                instance = it
            }
        }
        private fun buildDatabase(context: Context) = Room.databaseBuilder(
            context.applicationContext,
            AvCategoryDatabase::class.java,
            "categorydatabase"
        ).build()
    }
}